import {Injectable} from '@angular/core';
import {environment} from '../../environments/environment';

interface HttpInterceptorsConfig {
    gatewayServer: {
        enable: boolean,
        forward: boolean
    }
}

@Injectable()

export class ConfigService {

    imgHostname: string;
    hostname: string;
    geoServerHostname: string;
    uploadMock = true;

    constructor() {
        if (environment.production) {
            this.productionConfig();
            this.uploadMock = false;
        } else {
            this.defaultDevelopmentConfig();
        }
    }

    private defaultDevelopmentConfig() {
        // this.hostname = 'http://192.168.1.199:8080/api/v1'; // 本地
        // this.hostname = 'http://192.168.1.102:8000';
        // this.hostname = 'http://192.168.1.222:8000'  // 志强
        // this.hostname = 'http://192.168.1.222:8000';
        this.hostname = 'http://47.92.200.205:8080';
        this.imgHostname = 'http://47.92.200.205:8090';
        this.geoServerHostname = 'http://47.92.200.205:18080';
    }

    private productionConfig() {
        this.hostname = 'http://47.92.200.205:8080';
        this.imgHostname = 'http://47.92.200.205:8090';
        this.geoServerHostname = 'http://47.92.200.205:18080';
    }

    public fetchFromIconfontConfig() {
        return {scriptUrl: '//at.alicdn.com/t/font_1357911_551uj964i1b.js'};
    }

    /**
     * http拦截器网关服务 enable 为是否开启网关服务,forward是否开启端口转发
     */
    public httpInterceptorsConfig(): HttpInterceptorsConfig {
        return {
            gatewayServer: {
                enable: true,
                // false: /url => hostname + /url; http:url => http:url
                // true: /url 看forward逻辑，
                forward: true // 转发处理方式 true 为'http://47.92.200.205:8080/api-m/layerLabel'  false为'http://47.92.200.205:8091/layerLabel'
                // true               http://192.xxx => http://hostName/api-m/xx
                //                 http://not 192.xxx => http://not 192.xxx
            }
        }
    }
}
